package org.noote.roby.core;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class Main_Activity extends Activity implements OnClickListener {
	private static final String LOG_TAG = "Main_Activity";

	public static final String PREFS_NAME = "Robot_Core";
	public static final String PREFS_NAME_SERVER_PORT = "server_port";
	public static final String PREFS_NAME_CORE_NAME = "core_name";
	public static final String PREFS_BT_ADDRESS_DEVICE = "bluetooth_device";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button buttonCore = (Button)findViewById(R.id.buttonCore);
        buttonCore.setOnClickListener(this);
        
        Button buttonSettings = (Button)findViewById(R.id.buttonSettings);
        buttonSettings.setOnClickListener(this);
        
        BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
		if (mBluetoothAdapter == null) {
		    Toast.makeText(this, "No bluetooth adapter :(", Toast.LENGTH_LONG).show(); 
			return;
		}
		if (!mBluetoothAdapter.isEnabled()) {
		    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
		    startActivity(enableBtIntent);
		    return;
		}
    }

	@Override
	public void onClick(View v) {
		switch(v.getId())
    	{
	    	case R.id.buttonCore:
	    	{
	    		startAsRobotCore();
	    		break;
	    	}
	    	case R.id.buttonSettings:
	    	{
	    		launchSettings();
	    		break;
	    	}
    	}
	}

	private void startAsRobotCore() {
		Log.d(LOG_TAG, "startRobotCore()");
		
		Intent intent = new Intent(this, RobotCore_Activity.class);
		startActivity(intent);
	}
	
	private void launchSettings() {
		Log.d(LOG_TAG, "launchSettings()");
		
		Intent intent = new Intent(this, Preferences_Activity.class);
		startActivity(intent);
	}

	@Override
	public void onBackPressed()
	{
		Log.d(LOG_TAG, "finish()");
		
		finish();
	}
}